function getClosestSite(car_point,points) {
    // var pointA = new BMap.Point(coors[0],coors[1]);  // 创建点坐标A
    if(points==null || points.length==0) {
        return -1;
    }
    var index = -1;
    // var range = map.getDistance(car_point,points[0]).toFixed(2);;
    // for(let i = 1; i < points.length-1; i++) {
    //     var range1=map.getDistance(car_point,points[i]).toFixed(2);  //获取两点距离,保留小数点后两位
    //     if(range1 < range) {
    //         range = range1;
    //         index = i;
    //     }
    // }
    var range = ((car_point[0]-points[0][0])*(car_point[0]-points[0][0]) + (car_point[1]-points[0][1])*(car_point[1]-points[0][1])).toFixed(8);
    // console.log("range"+range);
    for(let i = 0; i < points.length; i++) {
        var range1 = ((car_point[0]-points[i][0])*(car_point[0]-points[i][0]) + (car_point[1]-points[i][1])*(car_point[1]-points[i][1])).toFixed(8);
        if (range1 <= range) {
            range = range1;
            index = i;
        }
    }
    // console.log("index:"+index);
    if(index!=-1) {
        $('.site').css("color", "gray");
        $('#site'+index).css("color", "#0278D8");
        var sites_left = points.length - index - 1;
        if(sites_left==0) {
            $('#sites_left').html("已在终点 / ");
            $('#time_left').html(" 0分钟");
        } else {
            console.log('sites_left:'+sites_left);
            console.log('time_left:'+getLeftTime(index));
            $('#sites_left').html("离终点"+sites_left+"站 / ");
            var time_left = getLeftTime(index);
            if(time_left!=-1) {
                $('#time_left').html("预计"+time_left+"分钟");
            } else {
                console("timesArr为空");
                $('#time_left').html("-");
            }

        }
    } else {
        console.log("points为空");
        $('#sites_left').html("离终点~站 / ");
        $('#time_left').html("预计~分钟");
    }
    return index;
}

function getLeftTime(index) {
    var time_left = -1;
    // console.log("timesArr"+timesArr);
    if(timesArr!==undefined && timesArr!=null && timesArr.length!=0) {
        time_left = 0;
        for (let i = index; i < timesArr.length; i++) {
            time_left = time_left + timesArr[i];
        }
    }
    // console.log("getLeftTime time_left-"+time_left);
    return time_left;
}



